
<style lang="less">
  .page__wrapper {
    width: 100%;
    height: 100%;
  }
  .balance_unlisted {
    .warm {
      background: #fce4d6;
    }
    .cold {
      background: #ddebf7;
    }
  }
</style>

<template>
  <div class="page__wrapper balance_unlisted">
    <simple-table :table-column="tableColumn" :table-data="tableData" :table-page-info="tablePageInfo" :table-data-count="tableDataTotalCount" @page-info-change="handlePageInfoChange">
      <template slot="searchSection">
        <simple-form v-model="searchModel" :form-field="searchFormField">
          <template slot="tableOperation">
            <el-button @click="handleDataSearch">{{$t('operation.search')}}</el-button>
            <el-button v-if="actionList.indexOf('export') >= 0" type="primary" @click="handleExportTemplate">模版</el-button>
            <el-button v-if="actionList.indexOf('export') >= 0" type="primary" @click="handleExport">导出</el-button>
            <aries-import v-if="actionList.indexOf('import') >= 0" tableName="Biz_Unlisted_Custody_Business"></aries-import>
          </template>
        </simple-form>
      </template>
      <template slot-scope="scope" slot="uploadquarter">
        {{ $getDictLabel({type: '季度', value: scope.row.uploadquarter}) }}
      </template>
      <template slot-scope="scope" slot="reformmethod">
        {{ $getDictLabel({type: '改革方式_未上市', value: scope.row.reformmethod}) }}
      </template>
      <template slot-scope="scope" slot="companyname">
        {{ scope.row.companyname | companynameFilter(orgList)}}
      </template>
      <template slot="operation" slot-scope="scope">
        <el-button v-if="actionList.indexOf('view') >= 0" circle icon="el-icon-search" :title="$t('operation.view')" @click="handleViewClick(scope.row)"></el-button>
        <el-button v-if="actionList.indexOf('edit') >= 0" circle icon="el-icon-edit" :title="$t('operation.edit')" @click="handleEditClick(scope.row)"></el-button>
        <el-button v-if="actionList.indexOf('del') >= 0" @click="deleteRecord(scope.row)" circle icon="el-icon-delete" :title="$t('operation.delete')"></el-button>
      </template>
    </simple-table>
    <detail-dialog :show-flag.sync="isShowDetailDialog" :detail-data="rowData" :view-flag="isViewFlag" :ext-data="{sys_mid, orgList}"></detail-dialog>
  </div>
</template>
<script>
/** 混入分页信息及数据总数信息 */
import pageMixins from '@/components/base/simple-table/page-mixins'
import detailDialog from './detail'
// import detailDialog from './detail'
const BASEURL = {
  list: '/Web/BizController/ajax.html?sys_method=GetListBySql&sys_objName=Biz_Unlisted_Custody_Business',
  delete: '/Web/BizController/ajax.html?sys_method=Delete&sys_objName=Biz_Unlisted_Custody_Business',
  getInitConfig: '/Web/SysAdmin/ajax.html?sys_method=GetInitConfig',
  getCombobox: '/Web/SysAdmin/ajax.html?sys_method=GetCombobox'
}
export default {
  name: 'balance_unlisted',
  mixins: [pageMixins],
  components: { detailDialog },
  data () {
    return {
      searchModel: {},
      /** 表格数据 */
      tableData: [],
      rowData: {},
      /** 是否显示详情页 dialog */
      isShowDetailDialog: false,
      /** 是否为查看数据 */
      isViewFlag: false,
      actionList: [],
      sys_mid: '',
      roleList: [],
      orgList: [],
      loadingFlag: {}
    }
  },
  filters: {
    companynameFilter (value, orgList) {
      let company = orgList.find(item => {
        return item.value === value
      })
      return company ? company.text : ''
    }
  },
  computed: {
    searchFormField () {
      return [
        { prop: 'companyname', label: this.$t('balance_unlisted.companyname'), type: 'Select', component: { clearable: true, optionList: this.orgList } },
        { prop: 'uploadyear', label: this.$t('balance_unlisted.uploadyear'), type: 'Datepicker', component: { clearable: true, type: 'year', valueFormat: 'yyyy' } },
        { prop: 'uploadquarter', label: this.$t('balance_unlisted.uploadquarter'), type: 'Select', component: { clearable: true, optionList: this.$getDictList('季度') } },
        { slotName: 'tableOperation', col: { span: 6, style: { textAlign: 'right' } }, labelWidth: '0' }
      ]
    },
    tableColumn () {
      return [
        { prop: 'companyname', label: this.$t('balance_unlisted.companyname'), slotName: 'companyname', width: 160, fixed: 'left' },
        { prop: 'uploadyear', label: this.$t('balance_unlisted.uploadyear'), width: 50, fixed: 'left' },
        { prop: 'uploadquarter', label: this.$t('balance_unlisted.uploadquarter'), slotName: 'uploadquarter', width: 70, fixed: 'left' },

        // 改革推进情况
        { label: this.$t('balance_unlisted.reform'),
          labelClassName: 'cold',
          children: [
            { label: this.$t('balance_unlisted.busiandlevethree'),
              children: [
                { prop: 'bizcategory1', label: this.$t('balance_unlisted.bizcategory1'), width: 80 },
                { prop: 'bizcategory2', label: this.$t('balance_unlisted.bizcategory2'), width: 80 }
              ]
            },
            { prop: 'reformmethod', label: this.$t('balance_unlisted.reformmethod'), slotName: 'reformmethod', width: 70 },
            { prop: 'totalprofit2015', label: this.$t('balance_unlisted.totalprofit2015'), width: 70 },
            { label: this.$t('balance_unlisted.unbusicharge'),
              children: [
                { prop: 'subtotalnonoperatingcost', label: this.$t('balance_unlisted.subtotalnonoperatingcost'), width: 70 },
                { prop: 'repairreconstructioncost', label: this.$t('balance_unlisted.repairreconstructioncost'), width: 95 },
                { prop: 'assetimpairmentloss', label: this.$t('balance_unlisted.assetimpairmentloss'), width: 85 },
                { prop: 'resettlementcost', label: this.$t('balance_unlisted.resettlementcost'), width: 70 }
              ]
            },
            { prop: 'reformmeasuresprogress', label: this.$t('balance_unlisted.reformmeasuresprogress'), width: 70 },
            { prop: 'existingproblem', label: this.$t('balance_unlisted.existingproblem'), width: 70 }
          ]
        },

        // 资产负债情况
        { label: this.$t('balance_unlisted.assetliabilitie'),
          labelClassName: 'warm',
          children: [
            { label: this.$t('balance_unlisted.endTerm'),
              children: [
                { label: this.$t('balance_unlisted.asset'),
                  children: [
                    { prop: 'totalassets', label: this.$t('balance_unlisted.totalassets'), width: 70 },
                    { prop: 'currencyfund', label: this.$t('balance_unlisted.currencyfund'), width: 70 },
                    { prop: 'stocknetreceivables', label: this.$t('balance_unlisted.stocknetreceivables'), width: 90 },
                    { prop: 'netvalueoffixedassets', label: this.$t('balance_unlisted.netvalueoffixedassets'), width: 60 },
                    { prop: 'buildingassets', label: this.$t('balance_unlisted.buildingassets'), width: 90 },
                    { prop: 'miningassets', label: this.$t('balance_unlisted.miningassets'), width: 70 }
                  ]
                },
                { label: this.$t('balance_unlisted.liability'),
                  children: [
                    { prop: 'totalliabilities', label: this.$t('balance_unlisted.totalliabilities'), width: 70 },
                    { prop: 'shorttermnegativeinterest', label: this.$t('balance_unlisted.shorttermnegativeinterest'), width: 60 },
                    { prop: 'assetsliabilities', label: this.$t('balance_unlisted.assetsliabilities'), width: 60 }
                  ]
                }
              ]
            }]
        },

        // 非矿区业务经营情况
        { label: this.$t('balance_unlisted.unminingareab'),
          labelClassName: 'cold',
          children: [
            { label: this.$t('balance_unlisted.currentmonth'),
              children: [
                { label: this.$t('balance_unlisted.businessincome'),
                  children: [
                    { prop: 'totalincomequarter', label: this.$t('balance_unlisted.totalincomequarter'), width: 60 },
                    { prop: 'internalcompanyincomequarter', label: this.$t('balance_unlisted.internalcompanyincomequarter'), width: 70 },
                    { prop: 'externalcompanyincomequarter', label: this.$t('balance_unlisted.externalcompanyincomequarter'), width: 70 }
                  ]
                },
                { label: this.$t('balance_unlisted.cost'),
                  children: [
                    { prop: 'totalcostquarter', label: this.$t('balance_unlisted.totalcostquarter'), width: 60 },
                    { prop: 'laborcostquarter', label: this.$t('balance_unlisted.laborcostquarter'), width: 70 },
                    { prop: 'interestexpensequarter', label: this.$t('balance_unlisted.interestexpensequarter'), width: 70 },
                    { prop: 'depreciationdepletionquarter', label: this.$t('balance_unlisted.depreciationdepletionquarter'), width: 70 }
                  ]
                },
                { prop: 'totalprofitquarter', label: this.$t('balance_unlisted.totalprofitquarter'), width: 70 }
              ]
            },
            { label: this.$t('balance_unlisted.currentyear'),
              children: [
                { label: this.$t('balance_unlisted.businessincome'),
                  children: [
                    { prop: 'totalincomeyear', label: this.$t('balance_unlisted.totalincomeyear'), width: 60 },
                    { prop: 'internalcompanyincomeyear', label: this.$t('balance_unlisted.internalcompanyincomeyear'), width: 70 },
                    { prop: 'externalcompanyincomeyear', label: this.$t('balance_unlisted.externalcompanyincomeyear'), width: 70 }
                  ]
                },
                { label: this.$t('balance_unlisted.cost'),
                  children: [
                    { prop: 'totalcostyear', label: this.$t('balance_unlisted.totalcostyear'), width: 60 },
                    { prop: 'laborcostyear', label: this.$t('balance_unlisted.laborcostyear'), width: 70 },
                    { prop: 'interestexpenseyear', label: this.$t('balance_unlisted.interestexpenseyear'), width: 70 },
                    { prop: 'depreciationdepletionyear', label: this.$t('balance_unlisted.depreciationdepletionyear'), width: 70 }
                  ]
                },
                { prop: 'totalprofityear', label: this.$t('balance_unlisted.totalprofityear'), width: 70 }
              ]
            }
          ]
        },

        // 矿区业务经营情况
        { label: this.$t('balance_unlisted.miningareab'),
          labelClassName: 'warm',
          children: [
            { label: this.$t('balance_unlisted.currentyear'),
              children: [
                { label: this.$t('balance_unlisted.businessincome'),
                  children: [
                    { prop: 'totalincome', label: this.$t('balance_unlisted.totalincome'), width: 50 },
                    { label: this.$t('balance_unlisted.extrevenue'),
                      children: [
                        { prop: 'totalexternalincome', label: this.$t('balance_unlisted.totalexternalincome'), width: 60 },
                        { prop: 'socialincome', label: this.$t('balance_unlisted.socialincome'), width: 60 },
                        { prop: 'industrialserviceincome', label: this.$t('balance_unlisted.industrialserviceincome'), width: 60 },
                        { prop: 'landleaseandotherincome', label: this.$t('balance_unlisted.landleaseandotherincome'), width: 85 },
                        { prop: 'incomingandoutgoing', label: this.$t('balance_unlisted.incomingandoutgoing'), width: 70 }
                      ]
                    },
                    { prop: 'listedcompany', label: this.$t('balance_unlisted.listedcompany'), width: 80 },
                    { prop: 'unlistedcompany', label: this.$t('balance_unlisted.unlistedcompany'), width: 90 }
                  ]
                },
                { label: this.$t('balance_unlisted.nonoperatingincome'),
                  children: [
                    { prop: 'totalnonoperatingincome', label: this.$t('balance_unlisted.totalnonoperatingincome'), width: 85 },
                    { prop: 'groupsubsidy', label: this.$t('balance_unlisted.groupsubsidy'), width: 70 }
                  ]
                },
                { label: this.$t('balance_unlisted.cost'),
                  children: [
                    { prop: 'totalcostmining', label: this.$t('balance_unlisted.totalcostmining'), width: 60 },
                    { prop: 'laborcostmining', label: this.$t('balance_unlisted.laborcostmining'), width: 70 },
                    { prop: 'depreciationdepletionmining', label: this.$t('balance_unlisted.depreciationdepletionmining'), width: 70 },
                    { prop: 'othermining', label: this.$t('balance_unlisted.othermining'), width: 50 }
                  ]
                },
                { prop: 'totalprofitmining', label: this.$t('balance_unlisted.totalprofitmining'), width: 70 }
              ]
            }
          ]
        },

        // 人员情况
        { label: this.$t('balance_unlisted.thestaff'),
          labelClassName: 'cold',
          children: [
            { label: this.$t('balance_unlisted.currentyearchange'),
              children: [
                {
                  label: this.$t('balance_unlisted.reduce'), // 减员
                  children: [
                    { prop: 'subtotalreduction', label: this.$t('balance_unlisted.subtotalreduction'), width: 70 },
                    { prop: 'naturalreduction', label: this.$t('balance_unlisted.naturalreduction'), width: 70 },
                    { prop: 'agreementcancellation', label: this.$t('balance_unlisted.agreementcancellation'), width: 70 },
                    { prop: 'specialtypeearlyretirement', label: this.$t('balance_unlisted.specialtypeearlyretirement'), width: 70 },
                    { prop: 'transferlisted', label: this.$t('balance_unlisted.transferlisted'), width: 70 },
                    { prop: 'otherreduction', label: this.$t('balance_unlisted.otherreduction'), width: 50 }]
                },
                { label: this.$t('balance_unlisted.increase'), // 增员
                  children: [
                    { prop: 'subtotalincrease', label: this.$t('balance_unlisted.subtotalincrease'), width: 70 },
                    { prop: 'undergraduate', label: this.$t('balance_unlisted.undergraduate'), width: 60 },
                    { prop: 'demobilizedserviceman', label: this.$t('balance_unlisted.demobilizedserviceman'), width: 70 },
                    { prop: 'otherincrease', label: this.$t('balance_unlisted.otherincrease'), width: 50 }
                  ]
                }
              ]
            },
            { label: this.$t('balance_unlisted.currentyear'), // 本年累计
              children: [
                { label: this.$t('balance_unlisted.currentemployeenum'), // 期末在职人数
                  children: [
                    { prop: 'totalcurrentemployee', label: this.$t('balance_unlisted.totalcurrentemployee'), width: 60 },
                    { prop: 'contractemployeecurrent', label: this.$t('balance_unlisted.contractemployeecurrent'), width: 60 },
                    { prop: 'marketemployeecurrent', label: this.$t('balance_unlisted.marketemployeecurrent'), width: 60 },
                    { prop: 'laboremployeecurrent', label: this.$t('balance_unlisted.laboremployeecurrent'), width: 70 }
                  ]
                },
                { prop: 'perlaborcost', label: this.$t('balance_unlisted.perlaborcost'), width: 60 }
              ]
            }
          ]
        },

        { label: this.$t('field.operation'), slotName: 'operation', width: 100, fixed: 'right', align: 'center' }

      ]
    }
  },
  /**
   * 注入到子组件
   */
  provide () {
    return { handleDataSearch: this.handleDataSearch }
  },
  methods: {
    handleDataSearch () {
      let params = Object.assign({}, this.tablePageInfo, { sys_mid: this.sys_mid, UserID: this.$store.state.app.userInfo.userid }, { sys_search: this.searchModel })
      if (arguments.length === 1) {
        this.loadingFlag = this.$loading({ fullscreen: false, target: this.$el, text: this.$t('tip.systemLoading') })
      }

      this.$axios
        .post(BASEURL.list, params)
        .then(resp => {
          this.tableData = resp.rows
          this.tableDataTotalCount = resp.total
        })
        .finally(() => {
          this.loadingFlag.close()
        })
    },
    handleInitData () {
      this.loadingFlag = this.$loading({ fullscreen: false, target: this.$el, text: this.$t('tip.systemLoading') })
      this.$axios.post(BASEURL.getInitConfig)
        .then(resp => {
          this.actionList = resp.actionKeys.split(',')
          this.sys_mid = resp.mid

          /** 设置列表及涉及主数据请求参数 */
          //  let params = Object.assign({}, this.tablePageInfo, { sys_mid: resp.mid, UserID: this.$store.state.app.userInfo.userid })
          let comboParams = { sys_json: JSON.stringify([{ ObjName: 'C_SYS_Role' }, { ObjName: 'C_SYS_Org' }]) }
          //   let loadingFlag = this.$loading({ fullscreen: false, target: this.$el, text: this.$t('tip.systemLoading') })

          this.$axios
            .post(BASEURL.getCombobox, comboParams)
            .then(resp => {
              this.roleList = resp.C_SYS_Role
              this.orgList = resp.C_SYS_Org
              this.handleDataSearch()
            })
        })
    },
    handleAddClick () {
      this.rowData = {}
      this.isViewFlag = false
      this.isShowDetailDialog = true
    },
    handleViewClick (row) {
      this.rowData = this.$_.cloneDeep(row)
      this.isViewFlag = true
      this.isShowDetailDialog = true
    },
    handleEditClick (row) {
      this.rowData = this.$_.cloneDeep(row)
      this.isViewFlag = false
      this.isShowDetailDialog = true
    },
    deleteRecord (row) {
      this.$msgbox({
        title: this.$t('tip.warning'),
        message: this.$t('tip.confirmDelete'),
        type: 'warning',
        showCancelButton: true,
        closeOnClickModal: false,
        closeOnPressEscape: false,
        beforeClose: (action, instance, done) => {
          if (action === 'confirm') {
            instance.confirmButtonLoading = true
            this.$axios
              .post(BASEURL.delete, { id: row.id, idField: 'id', sys_mid: this.sys_mid })
              .then(resp => {
                this.$message({ type: 'success', message: this.$t('tip.deleteSuccess') })
                done()
              })
              .finally(() => {
                instance.confirmButtonLoading = false
              })
          } else done()
        }
      })
        .then(() => {
          /** 如果本页面中只有一条数据 */
          /** 手动触发 simple-table 组件中的 watch，从而调用 mixins 中的请求数据方法 */
          if (this.tableData.length === 1) {
            this.tablePageInfo.page--
          } else {
            this.handleDataSearch()
          }
        })
    },
    handleExportTemplate () {
      this.$utils.fileExportAs('/Web/SysAdmin/ajax.html', {
        sys_objName: 'Biz_Unlisted_Custody_Business',
        sys_tableName: 'Biz_Unlisted_Custody_Business',
        sys_method: 'ExcelTemplate',
        sys_mid: this.sys_mid
      }, '未上市托管业务信息入系统模版.xls')
    },
    handleExport () {
      this.$utils.fileExportAs('/Web/BizController/ajax.html', {
        sys_objName: 'Biz_Unlisted_Custody_Business',
        sys_tableName: 'Biz_Unlisted_Custody_Business',
        sys_method: 'QueryExport',
        sys_mid: this.sys_mid,
        sys_search: this.searchModel,
        // 业务部分······
        dataStartRowIndex: 7, // 导出的excel对应的数据起始行
        dataStartCollumIndex: 0, // 导出的excel对应的数据起始列
        specialInfo: `${this.searchModel.uploadyear}年${this.$getDictLabel({ type: '季度', value: this.searchModel.uploadquarter })}        单位：万元，人`,
        specialStartRowIndex: 1, // 定位表头坐标
        specialStartCollumIndex: 0 // 定位表头坐标
      }, '未上市托管业务信息入系统.xls')
    }
  },
  mounted () {
    this.handleInitData()
  }
}
</script>
